package com.pine.dcts.task.dispatcher;

import com.pine.dcts.task.DefaultTaskPool;
import com.pine.dcts.task.TaskPool;
import com.pine.dcts.task.TaskRunner;
import org.springframework.stereotype.Component;

/**
 * @author xiaoyuan
 * @create 2021/1/13 17:27
 **/
@Component
public class DefaultTaskDispatcher implements TaskDispatcher {

    private static TaskPool taskRunnerPool;

    public DefaultTaskDispatcher() {
        taskRunnerPool = new DefaultTaskPool();
    }

    @Override
    public void start(TaskRunner taskRunner) {
        taskRunnerPool.submit(taskRunner);
    }

    @Override
    public void suspend(String taskId) {
        taskRunnerPool.stop(taskId);
    }

    @Override
    public void stop(String taskId) {
        taskRunnerPool.stop(taskId);
    }

    @Override
    public void stopAll() {
        taskRunnerPool.stopAll();
    }

    @Override
    public void shutdown() {
        taskRunnerPool.shutdown();
    }
}
